package com.hks360.car_treasure.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hks360.library.util.UIUtil;
import com.hks360.car_treasure.R;

import java.lang.reflect.Type;

/**
 * Created by rwq on 2016/3/3.
 */
public class MeView extends RelativeLayout{
    private ImageView iv_image;
    private TextView tv_text;
    public MeView(Context context) {
        this(context,null);
    }

    public MeView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context, attrs);
    }

    private void initView(Context context, AttributeSet attrs) {
        View view = View.inflate(context, R.layout.view_userinfo_user, MeView.this);
        iv_image = UIUtil.findViewById(view, R.id.iv_image);
        tv_text = UIUtil.findViewById(view,R.id.tv_text);
        int textid = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res-auto", "text", R.string.title);
        int imageid = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res-auto", "image", R.color.white);
        int textColor = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res-auto","textColor",R.color.gray_19);
        iv_image.setImageResource(imageid);
        tv_text.setText(textid);
        tv_text.setTextColor(getResources().getColor(textColor));
        String text = getResources().getString(textid);
        if(text.length() < 4){
            text = text.substring(0,1) + "       " + text.substring(1);
            tv_text.setText(text);
        }
    }

    public void setText(String text) {
        tv_text.setText(text);
    }

    public void setText(int resId) {
        tv_text.setText(resId);
    }
}
